<?php
/**
 * @author 	 	 supfire@sohu.com
 * @copyright    sns
 * @version      1.0
 * @name 		 user.php
 * @todo 		 用户action
 * @final 		 2008-08-05
 */
define('IN_YCTOOL', true);//定义该文件合法性
require_once('config.php');
require_once(DIR_COMM . 'common.php');

$action	= isset($_POST['action']) ? $_POST['action'] : "";
//不需要登录的处理
if($action == 'existemail')
{
    $email = isset($_POST['email']) ? $_POST['email'] : "";
    echo $user->getOneUser($email);
    exit;
}

//需要登录的处理 
$user->isLogin();
$userid = $user->userinfo['userid'];

if($action == 'setOnLine')
{
    $user->setOnLine($userid);
    exit;
}
//if($action == 'setuserlog')
//{
//    $user->setUserLog($userid);
//    exit;
//}

if($action == 'msg')
{
	require_once(DIR_MODEL . 'msg.func.php');
    echo haveNewNote($userid);
	exit;
}
if($action == 'urlGetTitle')
{

    function isUTF8($str)
    {
	if ($str === mb_convert_encoding(mb_convert_encoding($str, "UTF-32", "UTF-8"), "UTF-8", "UTF-32"))
	{
	    return true;
	} 
	else
	{
	    return false;
	}
    }

    $url = isset($_POST['url']) ? $_POST['url'] : "";
    if(!(preg_match("/^(http|https|ftp):(\/\/|\\\\)(([\w\/\\\+\-~`@:%])+\.)+([\w\/\\\.\=\?\+\-~`@\':!%#]|(&amp;)|&)+/i",$url) 
	|| strtolower(substr($url,0,7))=="mailto:"
	|| strtolower(substr($url,0,11))=="javascript:"))
    {
	$url = 'http://'.$url;
    }

    $txt = strtolower(@file_get_contents($url));
    if(!$txt)
    {
	$ch = @curl_init();     
	curl_setopt($ch,CURLOPT_URL,$url);        
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);        
	curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");         
	$txt = curl_exec($ch);        
	curl_close ($ch);
    }
    if($txt)
    {
	eregi("<title>(.*)</title>", $txt, $title);
	if(!isUTF8($txt))	
	{
	    $title[0] = iconv("gb2312", "utf-8", $title[0]) ;
	}
	$title = substr($title[0], 7, -8);  
    }
    echo $title;
    exit;
}
?>
